package com.loongtech.bi.manager.system;

import com.loongtech.bi.entity.system.EntityMonitorUserConfig;
import com.loongtech.core.jpa.manager.ManagerBase;
import com.loongtech.core.util.Utils;
import org.quartz.Scheduler;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class BiMonitorUserConfigManager extends ManagerBase<EntityMonitorUserConfig> {

	@Resource
	private Scheduler scheduler;

	private static final long serialVersionUID = 1L;

	/**
	 * 添加用户
	 */
	public void addUser(EntityMonitorUserConfig e) {
		persist(e);
	}

	/**
	 * 删除用户
	 */
	public void delUser(Integer id) {
			removeById(id);
	}

	/**
	 * 修改用户
	 */
	public void modifiyUser(EntityMonitorUserConfig e) {
		merge(e);
	}

	/**
	 * 获取用户列表
	 */
	public List<EntityMonitorUserConfig> queryList() {
		List<EntityMonitorUserConfig> list = findByQuery("from EntityMonitorUserConfig order by creatTime desc");
		return list;
	}

	/**
	 * 查询用户
	 */
	public List<EntityMonitorUserConfig> searchByCriteria(EntityMonitorUserConfig e) {
		List<Object> list = new ArrayList<Object>();
		StringBuffer hql = new StringBuffer(" from EntityMonitorUserConfig e where 1=1 ");
		if (!Utils.isEmptyStr(e.getEmail())) {
			hql.append(" and e.email like ?");
			list.add("%" + e.getEmail() + "%");
		}
        if (!Utils.isEmptyStr(e.getVoiceNum())) {
            hql.append(" and e.voiceNum like ?");
            list.add("%" + e.getVoiceNum() + "%");
        }
		if (!Utils.isEmptyStr(e.getPhoneNum())) {
			hql.append(" and e.phoneNum like ?");
			list.add("%" + e.getPhoneNum() + "%");
		}
		if (!Utils.isEmptyStr(e.getWeChat())) {
			hql.append(" and e.weChat like ?");
			list.add("%" + e.getWeChat() + "%");
		}
		if (!Utils.isEmptyStr(e.getUserName())) {
			hql.append(" and e.userName like ?");
			list.add("%" + e.getUserName() + "%");
		}
		hql.append(" order by e.creatTime desc");
		return findByQuery(hql.toString(), list.toArray());
	}
}
